package com.ss.android.newmedia.j;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.bytedance.article.common.c.TTUtils;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.util.NetworkUtils;

import org.json.JSONException;
import org.json.JSONObject;

public final class c extends AbsApiThread {
    private Context a;
    private Handler b;
    private boolean c;

    public c(Context arg1, Handler arg2, boolean arg3) {
        this.a = arg1;
        this.b = arg2;
        this.c = arg3;
    }

    public final void run() {
        Message v1_5;
        int v0 = 17;
        int v1 = 18;
        int v2 = 0;
        while (v2 < 2) {
            try {
                if (NetworkUtils.isNetworkAvailable(this.a)) {
                    StringBuilder v1_2 = new StringBuilder();
                    v1_2.append("http://ib.snssdk.com/service/settings/v2/");
                    v1_2.append("?app=1");
                    if (this.c) {
                        v1_2.append("&default=1");
                    }

                    String v1_3 = v1_2.toString();
                    if (v2 == 0 && !android.support.design.a.isTextEmpty(v1_3) && !v1_3.startsWith("https") && (v1_3.startsWith("http"))) {
                        v1_3 = v1_3.replaceFirst("http", "https");
                    }

                    v1_3 = NetworkUtils.doGet(-1, v1_3);
                    if (android.support.design.a.isTextEmpty(v1_3)) {
                    } else {
                        JSONObject v3 = new JSONObject(v1_3);
                        if (!isApiSuccess(v3)) {
                        } else {
                            JSONObject v1_4 = v3.optJSONObject("data");
                            com.ss.android.newmedia.j.c.c$a v3_1 = new com.ss.android.newmedia.j.c.c$a();
                            v3_1.a = this.c;
                            v3_1.b = v1_4.optJSONObject("default");
                            v3_1.c = v1_4.optJSONObject("app");
                            v1_5 = this.b.obtainMessage(10008);
                            v1_5.obj = v3_1;
                            this.b.sendMessage(v1_5);
                            return;
                        }
                    }
                } else {
                    v0 = 12;
                }
                break;
            } catch (JSONException v1_1) {
                v0 = TTUtils.getErrorCode(this.a, v1_1);
                break;
            } catch (Throwable v0_1) {
                v1 = TTUtils.getErrorCode(this.a, v0_1);
                if (AppLog.w() > 200) {
                    v0 = v1;
                    break;
                }
                ++v2;
                continue;
            }
        }
        v1_5 = this.b.obtainMessage(10009);
        v1_5.arg1 = v0;
        this.b.sendMessage(v1_5);
    }

    public final class c$a {
        public boolean a;
        public JSONObject b;
        public JSONObject c;

        public c$a() {

        }
    }
}

